<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/hdocs/style/css/topic.css" type="text/css" rel="stylesheet" />
<link href="/hdocs/style/css/common.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/hdocs/jquery/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="/hdocs/style/js/common.js"></script>
<script type="text/javascript">
function fileBrowser() {
	$("#fileUpload").click();
}
function changeBrowser() {
	$("#viewFile").val($("#fileUpload").val());
}
function imageSubmit() {
	var title = $("#title").val();
	var introduction = $("#introduction").val();
	var imagename = $("#imagename").val();
	var subjectid = $("#subjectid").val();
	var content = $("#content").val();
	var label = $("#label").val();
	$("#update_title").val(title);
	$("#update_introduction").val(introduction);
	$("#update_imagename").val(imagename);
	$("#update_subjectid").val(subjectid);
	$("#update_content").val(content);
	$("#update_label").val(label);
	$("#uploadArticleImageForm").submit();
}
</script>
<title>发表文章</title>
</head>
<body onload="alertMsg('$!messageCodeMap.get($!messageCode)')">
      #set ($menuIndex="topic") #parse("/inc/header.html")
      <div class="sqAd">
             <p class="helpCent">
             	<a href="/topic/addArticleInit.jsp">发表文章</a>
             </p>
      </div>
      <div class="centent">
            <div class="cenLe">
            	  <form id="uploadArticleImageForm" action="/topic/uploadArticleImages.jsp" style="display:none;" method="post" enctype="multipart/form-data">
					  <input id="fileUpload" type="file" onchange="changeBrowser()" name="fileUpload"/>
					  <input id="update_id" type="hidden" name="id" value="$!article.id"/>
					  <input id="update_title" type="hidden" name="title" value="$!article.title"/>
					  <input id="update_introduction" type="hidden" name="introduction" value="$!article.introduction"/>
					  <input id="update_imagename" type="hidden" name="imagename" value="$!article.imagename"/>
					  <input id="update_content" type="hidden" name="content" value="$!article.content"/>
					  <input id="update_subjectid" type="hidden" name="subjectid" value="$!article.subjectid"/>
					  <input id="update_label" type="hidden" name="label" value="$!article.label"/>
				  </form>
            	  <form id="mainFrom" action="/topic/addArticle.jsp" method="post">
                  <div class="fbTita">
                  		<span class="fbSpan">标题：</span>
                  		<input id="title" name="title" value="$!article.title" type="text" class="fbInp"/>
                  </div>
                  <p class="h10"></p>
                  <p class="h10"></p>
                  <div class="fbTitc">
                        <span class="fbSpan">引言：</span>
                        <textarea id="introduction" name="introduction" class="fbInIn">$!article.introduction</textarea>
                  </div>
                  <p class="h10"></p>
                  <p class="h10"></p>
                  <div class="fbTitc">
                        <span class="fbSpan">图片：</span>
                        <input id="viewFile" type="text" class="fbInp" readonly style="width:300px; margin-right:30px;"/>
                        <a href="javascript:fileBrowser();" class="fbSpan" style="margin-right:30px;">浏览本地照片</a>
                        <a href="javascript:imageSubmit();" class="fbSpan">上传</a>
                  </div>
                  <p class="h10"></p>
                  <p class="h10"></p>
                  #if($!article.imagename)
                  <p class="mivb" style="text-align:center;">
                  		<img id="img1" src="$!article.images[6]"/>
                  </p>
                  <p class="h10"></p>                 
                  <p class="h10"></p>
                  <input id="imagename" name="imagename" value="$!article.imagename" type="hidden"/>
				  #end                  
                  <div class="fbTitc">
                        <span class="fbSpan">内容：</span>
                        <textarea id="content" name="content" class="fbInContent">$!article.content</textarea>
                  </div>
                  <p class="h10"></p>
                  <p class="h10"></p>
                  <div class="chgIncm">
                  <span>发送到：</span>
                  <select id="subjectid" name="subjectid" style="margin:9px 0px;">
					  #foreach( $subject in $subjectList)
					  <option value="$!subject.id" #if($!article.subjectid == $!subject.id) selected #end>$!subject.title</option>
					  #end
				  </select>
                  </div>
                  <p class="h10"></p>
                  <p class="h10"></p>
                  <div class="chgIncm">
				 	  <span>标签：</span>
				 	  <input id="label" name="label" type="text" value="$!label" readonly class="fbInp"/>
				  </div>
				  <p class="h10"></p>
                  #parse("/inc/label.html")
                  <p class="h10"></p>
                  <p class="h10"></p>
                  <p class="fbSbtn">
						<input type="hidden" id="status" name="status" value="0"/>
                        <a href="javascript:addArticle(1);" class="fbsta"></a>
                        <a href="javascript:addArticle(0);" class="fbstb"></a>
                  </p>
                  </form>
            </div>
            <div class="cenRi">
                  <p class="fbFp">草稿箱（<a href="#">$!draftList.size()</a>）</p>
                  #foreach( $draft in $draftList)
                  <p class="fbRtcv">
                        <a href="/topic/updateArticleInit.jsp?id=$!draft.id" class="fbRta">$!draft.title</a>
                        <span  class="fbRtb">$!draft.modifydate</span>
                  </p>
                  #end
            </div>
      </div>
      #parse("/inc/footer.html")
</body>
</html>
<script type="text/javascript">
function addArticle(status) {
	if(!confirm("您确认保存文章吗?")){
		 return;
	}
	if(!validate()){
		return;
	}
	$("#status").val(status);
	$("#mainFrom").submit();
}

function validate(){
	var title = $("#title").val();
	if(title==null||title==''){
		alert("文章标题不能为空！");
		return false;
	}
	if(title.length>18){
		alert("文章标题不能过长！");
		return false;
	}
	var imagename = $("#imagename").val();
	if(imagename==null||imagename==''){
		alert("文章图片不能为空！");
		return false;
	}
	var content = $("#content").val();
	if(content==null||content==""){
		alert("文章内容不能为空！");
		return false;
	}
	return true;
}
</script>